<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script>
	$(function() {
		$("#btnLogin").click(				
				function() {
					// 发送异步请求，设置参数
					$.ajax({
						url : 'LoginServlet',
						type : 'post',
						data : {
							username : $("#username").val(),
							userpwd : $("#userpwd").val()
						},
						dataType : 'json',  //存在问题，能判断成功，失败显示parsererror
						success : function(data) {
							//如果有name属性代表登陆成功，否则为失败
 							if (data.name) {
								$(".divTitle").html("<span>登陆成功<span>");
								$(".clsShow").html("欢迎你："+data.name); 
							} else {
								$("#divError").html("用户名或密码错误").show();
							}
						},
						error : function(xhr, msg) {
							alert(msg);
						}
					});
				});
	});
</script>
<body>
	<div class="container"
		style="width: 300px; height: 300px; margin: 0px auto">
		<form role="form" class="form-inline">
			<br /> <br />
			<div id="divTitle"></div>
			<div id="divError"></div>
			<div class="clsShow"></div>
						
			<div class="form-group">
				<input type="text" class="form-control" id="username"
					placeholder="请输入用户名">
			</div>
			<br />
			<div class="form-group">
				<input type="password" class="form-control" id="userpwd"
					placeholder="请输入密码">
			</div>
			<br /> <br />
			<button id="btnLogin" type="button" class="btn btn-info">登录</button>
		</form>
	</div>

</body>
</html>